package yxy.game.pm2.command.arena;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ArenaMessage;
import yxy.game.pm2.module.arena.ArenaHandle;
import yxy.game.pm2.module.tip.TipHandle;
import yxy.game.pm2.module.tip.TipType;

/** 竞技场 挑战记录 */
@MessageType(proto = Command.ArenaChanllengeRecord, classtype = ArenaMessage.ArenaChanllengeRecordRequest.class)
public class CMD_ArenaChanllengeRecord extends Command<ArenaMessage.ArenaChanllengeRecordRequest> {

	@Override
	public void execute(MessageSource messageSource, ArenaMessage.ArenaChanllengeRecordRequest request) {
		String playerCode = messageSource.getTag();

		ArenaMessage.ArenaChanllengeRecordResponse.Builder response = ArenaMessage.ArenaChanllengeRecordResponse.newBuilder();

		try {
			Result result = new ArenaHandle().record(playerCode, response);
			send(messageSource, response, result);
		} catch (Exception e) {
			e.printStackTrace();
			send(messageSource, response, Result.DataError);
		}

		new TipHandle().updateTip(playerCode, TipType.主城_竞技场建筑, false);// 看了记录就把红点去
	}

	private void send(MessageSource messageSource, ArenaMessage.ArenaChanllengeRecordResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}